<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="i1" />
		<input type="text" id="i2" />
		<input type="button" value="加" onclick="fn5(1)" />
		<input type="button" value="减" onclick="fn5(2)" />
		<input type="button" value="乘" onclick="fn5(3)" />
		<input type="button" value="除" onclick="fn5(4)" />
		<hr>
		<div id="mydiv">
		</div>
		<script type="text/javascript">
			function fn1() {
				/* var i1 = document.getElementById("i1");
				var i2 = document.getElementById("i2");
				var mydiv = document.getElementById("mydiv"); */
				mydiv.innerText = i1.value * 1 + i2.value * 1;
			}

			function fn2() {
				mydiv.innerText = i1.value - i2.value;
			}

			function fn3() {
				mydiv.innerText = i1.value * i2.value;
			}

			function fn4() {
				mydiv.innerText = i1.value / i2.value;
			}

			function fn5(x) {
				//判断是否是数值
				if (isNaN(i1.value) || isNaN(i2.value)) {
					mydiv.innerText = "输入错误";
					return; //结束当前方法
				}
				switch (x) {
					case 1:
						mydiv.innerText=i1.value*1+i2.value*1;
						break;
					case 2:
						mydiv.innerText=i1.value-i2.value;
						break;
					case 3:
						mydiv.innerText=i1.value*i2.value;
						break;
					case 4:
						mydiv.innerText=i1.value/i2.value;
						break;
				}
			}
		</script>
	</body>
</html>
